package com.neusoft.neuiotms.common.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.web.dto.result.PageResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultListDTO;
import com.neusoft.bizcore.web.support.Searchable;
import com.neusoft.neuiotms.common.dto.DictionaryTypeDTO;
import com.neusoft.neuiotms.common.service.DictionaryTypeService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "字典表解释说明")
@RestController
@RequestMapping(value = "/api/w/dictionaryType")
public class DictionaryTypeController {

    @Autowired
    private DictionaryTypeService dictionaryDescService;

    @ApiOperation("查询所有码表")
    @GetMapping
    public ResultListDTO<DictionaryTypeDTO> index(final Searchable searchable) {
        final List<DictionaryTypeDTO> DTOs = this.dictionaryDescService.findAll(searchable);
        final ResultListDTO<DictionaryTypeDTO> result = ResultListDTO.success(DTOs);
        return result;
    }

    @ApiOperation("分页查询所有码表")
    @GetMapping("/p")
    public PageResultDTO<DictionaryTypeDTO> search(final Pageable pageable, final Searchable searchable) {
        return PageResultDTO.success(this.dictionaryDescService.search(pageable, searchable));
    }

    @ApiOperation("创建码表")
    @PostMapping("")
    public ResultDTO<DictionaryTypeDTO> create(@RequestBody final DictionaryTypeDTO dto) {
        final DictionaryTypeDTO result = this.dictionaryDescService.create(dto);
        return ResultDTO.success(result);
    }

    @ApiOperation(value = "修改码表")
    @PutMapping("/{id}")
    public ResultDTO<DictionaryTypeDTO> update(@PathVariable final Long id,
            @RequestBody final DictionaryTypeDTO dto) {
        final DictionaryTypeDTO result = this.dictionaryDescService.update(id, dto);
        return ResultDTO.success(result);
    }

    @ApiOperation("码表详情")
    @GetMapping("/{id}")
    public ResultDTO<DictionaryTypeDTO> details(@PathVariable final Long id) {
        final DictionaryTypeDTO dto = this.dictionaryDescService.details(id);
        return ResultDTO.success(dto);
    }

    @ApiOperation("删除码表")
    @DeleteMapping("/{id}")
    public ResultDTO<Void> delete(@PathVariable final Long id) {
        this.dictionaryDescService.delete(id);
        return ResultDTO.success();
    }
}
